import request from '@/utils/request'

// 步态分析数据类型
export interface GaitAnalysisData {
  'joint_data.csv': string
  'raw_capture.mp4': string
  'annotated_video.mp4': string
  'world_landmarks.csv': string
  'z_differ_APPROACHING.png': string
  'gait_analysis_report.json': string
  'gait_events_analysis.json': string
  'enriched_steps_LEAVING.json': string
  'enriched_steps_APPROACHING.json': string
  'annotated_video_with_gait_event.mp4': string
  'extrema_list_APPROACHING_Mediapipe_Kalman.png': string
  'gait_segments_APPROACHING_Mediapipe_Raw_Mediapipe_Kalman.png': string
}

// 面部表情分析数据类型
export interface FacialExpressionData {
  'event_pie.png': string
  'sentiment_pie.png': string
  'sentiment_analysis.png': string
  'facemesh_processed_video.mp4': string
}

// 眼动追踪数据类型
export interface EyeTrackingData {
  'gaze_video_20250818.mp4': string
}

// 手写数据类型
export interface HandwritingData {
  'tablet_trace_video_tablet_data_20250818143029.csv.mp4': string
  'tablet_trace_video_tablet_data_20250818143124.csv.mp4': string
  'tablet_trace_static_tablet_data_20250818143029.csv.png': string
  'tablet_trace_static_tablet_data_20250818143124.csv.png': string
}

// 语音分析数据类型
export interface SpeechAnalysisData {
  'dialogue.jsonl': string // 要显示
}

// 分析记录状态类型
export type AnalysisStatus = 'initialized' | 'processing' | 'completed' | 'failed'

// 完整的分析记录响应接口
export interface QsAndVideoResponse {
  log_id: number // 主键，不用管
  medical_record_number: string // 医疗记录号
  created_at: string // 创建时间UTC
  created_date: string // 创建时间（东八区时间）
  status: AnalysisStatus // 预留，不用管
  gait_analysis: GaitAnalysisData | null
  facial_expression: FacialExpressionData | null
  eye_tracking: EyeTrackingData | null
  handwriting: HandwritingData | null
  speech_analysis: SpeechAnalysisData | null
  semantic_analysis: any | null
  raw_result_path: string | null
}

// 获取分析记录查询参数
export interface FetchQsAndVideoParams {
  page?: number
  page_size?: number
  medical_record_number?: string
  created_date?: string
  status?: AnalysisStatus
}

export const fetchQsAndVideo = (params: FetchQsAndVideoParams): Promise<QsAndVideoResponse> => {
  return request({
    url: `/history/records/${params.medical_record_number}/${params.created_date}`,
    method: 'get',
    params,
  })
}

// 打评分
export const rate = (data: {
  category:
    | 'facial_expression'
    | 'gait_analysis'
    | 'eye_tracking'
    | 'handwriting'
    | 'speech_analysis'
  score: number
  medical_record_number: string
  created_date: string
}): Promise<any> => {
  return request({
    url: `/v1/rating/records/${data.medical_record_number}/${data.created_date}`,
    method: 'post',
    data,
  })
}
